package cn.wen.yaling.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wen.yaling.aop.annotation.operation.OperationLogger;
import cn.wen.yaling.aop.annotation.repeat.AvoidRepeatableCommit;
import cn.wen.yaling.commons.vo.PermissionAddVO;
import cn.wen.yaling.commons.vo.PermissionUpdateVO;
import cn.wen.yaling.commons.vo.RoleAddVO;
import cn.wen.yaling.commons.vo.RoleUpdateVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yaling.commons.entity.PermissionEntity;
import cn.wen.yaling.xo.service.PermissionService;
import cn.wen.yaling.commons.utils.PageUtils;
import cn.wen.yaling.commons.utils.ResultEntity;



/**
 * 
 *
 * @author FY
 * @email 932043654@qq.com
 * @date 2022-08-13 02:07:37
 */
@RestController
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @ApiOperation(value = "获取权限信息列表", notes = "获取权限信息列表")
    @GetMapping("/admin/permission/list")
    public ResultEntity getList() {
        return permissionService.getPermissionList();
    }

    @AvoidRepeatableCommit
    @OperationLogger(value = "新增权限信息")
    @ApiOperation(value = "新增权限信息", notes = "新增权限信息")
    @PostMapping("/admin/permission/add")
    public ResultEntity add(@RequestBody PermissionAddVO permissionAddVO) {
        return permissionService.addPermission(permissionAddVO);
    }

    @OperationLogger(value = "更新权限信息")
    @ApiOperation(value = "更新权限信息", notes = "更新权限信息")
    @PostMapping("/admin/permission/update")
    public ResultEntity update(@RequestBody PermissionUpdateVO permissionUpdateVO) {
        return permissionService.editPermission(permissionUpdateVO);
    }

    @OperationLogger(value = "删除权限信息")
    @ApiOperation(value = "删除权限信息", notes = "删除权限信息")
    @PostMapping("/admin/permission/delete")
    public ResultEntity delete(@RequestParam("permissionId") Integer permissionId) {
        return permissionService.deleteBatchPermission(permissionId);
    }

    @ApiOperation(value = "获取简易的权限信息", notes = "获取简易的权限信息")
    @GetMapping("/admin/permission/simple/list")
    public ResultEntity simpleList() {
        return permissionService.getSimplePermissionList();
    }

    @ApiOperation(value = "获取角色分配权限目录", notes = "获取角色分配权限目录")
    @GetMapping("/admin/permission/tree/list")
    public ResultEntity getPermissionTreeList() {
        return permissionService.getPermissionTreeList();
    }

}
